@extends('admin.layout.base')
@section('styles')
@endsection
@section('content')
    <div class="panel-content" id="app" v-cloak>
        <div class="panel-body panel-info">
            <el-form :model="form" ref="form" class="form" label-width="100px" >
                <div class="panel-header"> <div class="panel-title"> 消息发送 </div> </div>
                <div class="panel-main">
                    <el-form-item :rules="[{ required: true, message: '请填写标题', trigger: 'blur'}]" label="标题：" prop="title">
                        <el-input clearable v-model="form.title" placeholder="请填写标题"></el-input>
                    </el-form-item>
                    <el-form-item required label="类别：" prop="type">
                        <el-radio-group v-model="form.type">
                            <el-radio :label="1" border>全部</el-radio>
                            <el-radio :label="2" border>供应商</el-radio>
                            <el-radio :label="3" border>人力HR</el-radio>
                            <el-radio :label="4" border>其他</el-radio>
                            <el-radio :label="5" border>中标记录</el-radio>
                        </el-radio-group>
                    </el-form-item>
                    <el-form-item v-if="form.type == 4" :rules="[{ required: true, message: '请填写消息接收用户ID', trigger: 'blur'}]" label="用户ID：" prop="user_ids">
                        <el-input clearable v-model="form.user_ids" placeholder="请填写消息接收用户ID，多个用户ID请用-隔开，例：152-362-456"></el-input>
                    </el-form-item>
                    <el-form-item label="内容：" :rules="[{ required: true, message: '请填写内容', trigger: 'blur'}]" prop="content">
                        <el-input type="textarea" rows="15" v-model="form.content" placeholder="请填写内容"></el-input>
                    </el-form-item>
                </div>
                <el-form-item style="padding-left: 150px;margin-top: 50px">
                    <el-button type="primary" @click="update()">确 定</el-button>
                    <el-button @click="back()" style="margin-left: 50px">返 回</el-button>
                </el-form-item>
            </el-form>
        </div>
    </div>
@endsection
@section('scripts')
    <script>
        let app = new Vue({
            el: '#app',
            data: function() {
                return {
                    form:{title:'', content:'', type:1, user_ids:''},
                }
            },
            created(){

            },
            methods: {
                //返回
                back(){
                    window.history.go(-1);
                },
                //更新
                update(){
                    this.form._token = "{{csrf_token()}}";
                    this.$refs['form'].validate((valid) => {
                        if (valid) {
                            let that = this;
                            $.post("{{ route('admin.message.update') }}",this.form,function (res) {
                                if(res.code){
                                    that.$message.error(res.msg);
                                }else{
                                    that.$message({
                                        type: 'success',
                                        duration: '1000',
                                        message: res.msg,
                                        onClose:() =>{
                                            window.history.go(-1);
                                        }
                                    });
                                }
                            },'JSON');
                        }
                    });
                },
            }
        });
    </script>
@endsection
